package com.huawei.zyb.taskManager.domain.task.valueobject;

import java.util.Objects;

/**
 * 任务标题值对象
 * 业务规则：不能为空且长度不超过100字符
 */
public final class TaskTitle {
    private static final int MAX_LENGTH = 100;
    private final String value;

    private TaskTitle(String value) {
        this.value = Objects.requireNonNull(value, "任务标题不能为空");
        if (value.trim().isEmpty()) {
            throw new IllegalArgumentException("任务标题不能为空字符串");
        }
        if (value.length() > MAX_LENGTH) {
            throw new IllegalArgumentException("任务标题长度不能超过" + MAX_LENGTH + "字符");
        }
    }

    public static TaskTitle of(String value) {
        return new TaskTitle(value);
    }

    public String getValue() {
        return value;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) return true;
        if (obj == null || getClass() != obj.getClass()) return false;
        TaskTitle taskTitle = (TaskTitle) obj;
        return Objects.equals(value, taskTitle.value);
    }

    @Override
    public int hashCode() {
        return Objects.hash(value);
    }

    @Override
    public String toString() {
        return "TaskTitle{" + value + "}";
    }
}